﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Qplus.Commands;
using System.Diagnostics;

namespace Qplus.UI
{
    public partial class PopupUserInfo : UserControl
    {
        bool isFriend;
        public PopupUserInfo()
        {
            InitializeComponent();
            try
            {
                name = UIData.getInstance().userInfo.name;
                sex = UIData.getInstance().userInfo.sex;
                mail = UIData.getInstance().userInfo.mail;
                birthday = UIData.getInstance().userInfo.birthday;
                canStrangerChat = UIData.getInstance().userInfo.canStrangerChat;
                level = UIData.getInstance().userInfo.level;
                headType = UIData.getInstance().userInfo.headType;
                headValue = UIData.getInstance().userInfo.headValue;
                MightList = UIData.getInstance().userInfo.MightList;
                Current_max_friend_count = UIData.getInstance().userInfo.Current_max_friend_count;
                Max_friend_count_upper = UIData.getInstance().userInfo.Max_friend_count_upper;
                Task_score = UIData.getInstance().userInfo.Task_score;
                appList = UIData.getInstance().userInfo.appList;
            }
            catch (Exception ee)
            {
                Debug.WriteLine(ee.Message);
            }
        }

        #region
        public string name ;
        public int sex ;
        public string mail ;
        public string birthday ;
        public int canStrangerChat ;
        public string level ;
        public int headType ;
        public string headValue ;
        public MightList[] MightList ;
        public string Current_max_friend_count ;
        public string Max_friend_count_upper ;
        public string Task_score ;
        public appList[] appList ;
        //public string name { get; set; }
        //public int sex { get; set; }
        //public string mail { get; set; }
        //public string birthday { get; set; }
        //public int canStrangerChat { get; set; }
        //public string level { get; set; }
        //public int headType { get; set; }
        //public string headValue { get; set; }
        //public MightList[] MightList { get; set; }
        //public string Current_max_friend_count { get; set; }
        //public string Max_friend_count_upper { get; set; }
        //public string Task_score { get; set; }
        //public appList[] appList { get; set; }
        #endregion
        public string userName
        {
            set { nameTxt.Text = value; }
            get { return nameTxt.Text; }
        }
        public bool IsFriend
        {
            set
            {
                isFriend = value;
                if (isFriend)
                    starChatBtnEx.Visibility = System.Windows.Visibility.Collapsed;
            }
            get { return isFriend; }
        }
        public string userAge
        {
            set { ageTxt.Text = value; }
        }
        public sexEnum userSex
        {
            set
            {
                switch (value)
                {
                    case sexEnum.male:
                        sexTxt.Text = "男";
                        break;
                    case sexEnum.female:
                        sexTxt.Text = "女";
                        break;
                    case sexEnum.unknow:
                        sexTxt.Text = "";
                        break;
                    default:
                        sexTxt.Text = "";
                        break;
                }
            }
        }

        private void closeBtnEx_Click(object sender, RoutedEventArgs e)
        {
            this.CloseMeAsPopup();
        }

        private void starChatBtnEx_Click(object sender, RoutedEventArgs e)
        {
            this.CloseMeAsPopup();
            UIData uidata = UIData.getInstance();
            beans.QUser quser = new beans.QUser();
            beans.UserInfo quinfo = new beans.UserInfo();
            AddFriendCommand command_AddFriend = new AddFriendCommand(
                uidata.L2C.UserID.ToString(),
                System.Text.Encoding.UTF8.GetString( uidata.L2C.Key,0,uidata.L2C.Key.Length),
                quser,quinfo);
            command_AddFriend.set(0, 8615);
            command_AddFriend.execute(uidata.L2C.UpgradeURL);
            (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/UI/ChatFriend.xaml?nickName=" + userName, UriKind.Relative));
        }

        private void reportBtnEx_Click(object sender, RoutedEventArgs e)
        {
            this.CloseMeAsPopup();
            PopupContainer pc = new PopupContainer((Application.Current as App).RootFrame.Content as PhoneApplicationPage);// ((Application.Current.RootVisual as PhoneApplicationFrame).GetVisualDescendants().OfType<PhoneApplicationPage>().FirstOrDefault());
            ReportControl popupUserInfo = new ReportControl() { userName = this.nameTxt.Text};
            pc.Show(popupUserInfo);
        }
    }
}
